﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRProject.Code.DTO;
using HRProject.Code.DAO;
using System.Collections.Generic;

namespace HRProject
{
    public partial class Front5 : System.Web.UI.MasterPage
    {
        private BLRecordType companyRecordType;

        public BLRecordType CompanyRecordType
        {
            get { return companyRecordType; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            {
                RecordTypeDAO recordTypeDao = new RecordTypeDAO();
                BLRecordType recordTypeFilter = new BLRecordType();
                recordTypeFilter.Id = Guid.Empty;
                recordTypeFilter.Name = string.Empty;
                recordTypeFilter.Parent = new BLRecordType();
                recordTypeFilter.Parent.Id = Guid.Empty;
                List<BLRecordType> assetTypes = recordTypeDao.Search(recordTypeFilter);
                companyRecordType = recordTypeDao.BuildTree(assetTypes);
            }
        }

        public void PrintRecordType(BLRecordType recordType)
        {
            Response.Write("<li id=\"");
            Response.Write(recordType.Id);
            Response.Write("\"><a href=\"javascript:void(0);\">");
            Response.Write(recordType.Name);
            Response.Write("</a>");
            if (recordType.Children.Count > 0)
            {
                Response.Write("<ul>");
            }
            foreach (BLRecordType child in recordType.Children)
            {
                PrintRecordType(child);
            }
            if (recordType.Children.Count > 0)
            {
                Response.Write("</ul>");
            }
            Response.Write("</li>");
        }
    }
}
